#include<iostream>
#include<cstring>
using namespace std;
const int N = 2010;
int arr[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		memset(arr, 0, sizeof(arr));
		cin >> n;
		int mi = 1e9;
		int ma = -1e9;
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
			if (arr[i] > ma) {
				ma = arr[i];
			}
			if (arr[i] < mi) {
				mi = arr[i];
			}
		}
		if (n == 1) {
			cout << 0 << endl;
		}
		else {
			cout << ma - mi << endl;
		}
	}
	return 0;
}